package com.zsl.swing.redis.desktop.window.panel;

import com.zsl.swing.redis.desktop.model.NodeEntity;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.basic.BasicSplitPaneDivider;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import java.awt.*;

/**
 * 操作面版
 */
public class ZslDbOptPanel extends JSplitPane {

    /**
     * 数据库连接信息
     */
    private final NodeEntity entity;

    private final ZslKeyQueryPanel zslKeyQueryPanel;

    private final ZslValueShowPanel zslValueShowPanel;

    public static ZslDbOptPanel getInstance(NodeEntity entity){
        ZslDbOptPanel instance = new ZslDbOptPanel(entity);
        return instance;
    }

    private ZslDbOptPanel(NodeEntity entity){
        super();
        this.entity = entity;
        this.zslValueShowPanel = new ZslValueShowPanel(this);
        this.zslKeyQueryPanel = new ZslKeyQueryPanel(this);

        this.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
        this.setContinuousLayout(true);
//        this.setOneTouchExpandable(true);
        this.setLeftComponent(this.zslKeyQueryPanel);
        this.setRightComponent(this.zslValueShowPanel);
        this.setDividerLocation(650);
        this.setDividerSize(10);
        this.setContinuousLayout(true);

        this.setUI(new BasicSplitPaneUI(){

            public BasicSplitPaneDivider createDefaultDivider() {
                return new BasicSplitPaneDivider(this) {


                    public void setBorder(Border b) {
                    }

                    @Override
                    public void paint(Graphics g) {
                        g.setColor(Color.WHITE);
                        g.fillRect(0, 0, getSize().width, getSize().height);
                        super.paint(g);
                    }
                };
            }

        });
        this.setVisible(true);

    }



    public void add(Component f,JPanel t, GridBagConstraints constraints, int x, int y, int w,int h) {
        constraints.gridheight = h;
        constraints.gridwidth = w;
        constraints.gridx = x;
        constraints.gridy = y;
        t.add(f,constraints);
    }

    public NodeEntity getEntity(){
        return this.entity;
    }

    public ZslKeyQueryPanel getKeyQueryPanel(){
        return this.zslKeyQueryPanel;
    }

    public ZslValueShowPanel getValueShowPanel(){
        return this.zslValueShowPanel;
    }
}
